package com.lifa.controller;

import com.lifa.dao.JicunDao;
import com.lifa.entity.Huiyuan;
import com.lifa.entity.Jicun;
import com.lifa.entity.SPquchushijian;
import com.lifa.service.JicunService;
import com.lifa.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/jicun")
@Scope("prototype")
public class JicunController {
    @Autowired
    private JicunService jicunService;
    @Autowired
    private JicunDao jicunDao;
    /**
     * 查询
     * @return
     */
    @RequestMapping("/ji1")
    @ResponseBody
    public List<Jicun> list(){
        return jicunService.list();
    }

    @RequestMapping("/queryByNames")
    @ResponseBody
    public Map<String,Object> queryPageByName(String name,int offset,int limit){
        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",jicunDao.queryPage(name,offset,limit)) ;
        map.put("total",jicunDao.getTotalCount(name)) ;
        return  map ;
    }

    /**
     * 获取到会员id
     * @param huiyuan_Id
     * @return
     */
    @RequestMapping("/queryId")
    @ResponseBody
    public Jicun queryId(int huiyuan_Id){
        return jicunService.queryId(huiyuan_Id);
    }

    /**
     * 根据会员id修改信息
     * @param jicun
     * @return
     */
    @RequestMapping("/xiugai")
    @ResponseBody
    public int xiugai(Jicun jicun){
        return jicunService.update(jicun);
    }

    /**
     * 添加商品取出记录
     * @param
     * @return
     */
    @RequestMapping("/tiajiaSP")
    @ResponseBody
    public int tiajia(SPquchushijian sPquchushijian){
        return jicunService.insert(sPquchushijian);
    }

    /**
     * 查询会员信息
     * @return
     */
    @RequestMapping("/chaxhy")
    @ResponseBody
    public List<Huiyuan> chahy(int huiyuan_Id){
        return jicunService.cha(huiyuan_Id);
    }

    /**
     * 随机生成单号
     * @return
     */
    @RequestMapping("/dhao")
    @ResponseBody
    public String dhao(){
        return StringUtil.shengChengDdid();
    }

    /**
     * 添加寄存信息
     * @param jicun
     * @return
     */
    @RequestMapping("/tiajiaJC")
    @ResponseBody
    public int tiajia(Jicun jicun){
        return jicunService.add(jicun);
    }
}
